//张
//专辑页

<template>
  <div class="album_info_box">
    <top_block
      :cover_img_path="cover_img_path"
      :playlist_album_name="name"
      :author_name="author"
      :issue_time="issue_time"
      :brief_info="brief_info"
      :like_data="like_data"
      :comment_data="comment_data"
      :like_img_path="like"
      ref="top"
    />
    <bottom_block
      :list="music_list"
      :commentList="comment_list"
      :pageList="pageCnt"
    />
  </div>
</template>

<script>
import bottom_block from "../components/playlist_album/bottom_block.vue";
import top_block from "../components/playlist_album/top_block.vue";
export default {
  name: "album_info",
  components: {
    bottom_block,
    top_block,
  },
  data() {
    return {
      cover_img_path: "",
      name: "专辑名",
      author: "作者名",
      issue_time: "2022.3.7",
      brief_info:
        "这是一个关于专辑的介绍，大家好我又来了，我又来凑字数了，至于具体怎么凑字数我还在思考，这真的不是一个简单的问题，真是让人掉头发，我瞅瞅我凑字数凑得咋样啦？好像还差一点点，应该差不多了。",
      like_data: 0,
      comment_data: 0,
      music_list: [],
      comment_list: [], //评论列表
      id: 0,
      songCnt: 1, //歌曲总数
      pageCnt: 2, //页码数
      flag: 0, //1为专辑 2为歌单
      isStar: -1, //是否已关注  0未关注 1已关注
    };
  },
  watch: {
    isStar: {
      handlder(val) {
        if (val == 0) {
          this.$refs.top.isStar = false;
        } else if (val == 1) {
          this.$refs.top.isStar = true;
        }
      },
      immediate: true,
    },
  },
  created() {
    this.id = this.$route.query.id;
    let flag = this.$route.query.flag;
    this.flag = flag;
    //登录时
    if (sessionStorage.getItem("token")) {
      //flag==1为专辑
      if (flag == 1) {
        //专辑歌曲信息以及歌曲列表
        this.$http
          .get("/album", {
            headers: {
              Authorization:
                "Bearer " + JSON.parse(sessionStorage.getItem("token")),
            },

            params: {
              album_id: this.$route.query.id,
            },
          })
          .then((res) => {
            this.music_list = res.data.data.list;
            this.cover_img_path = res.data.data.cover;
            this.name = res.data.data.name;
            this.author = res.data.data.author;
            this.brief_info = res.data.data.description;
            this.issue_time = res.data.data.publish;
            this.like_data = res.data.data.fans;
            this.comment_data = res.data.data.comments;
            //处理页数问题
            let Cnt = res.data.data.list.length;
            this.songCnt = Cnt;
            this.pageCnt = Math.ceil(this.songCnt / 8);
            this.isStar = res.data.data.isStar;
            if (res.data.data.isStar == 1) {
              this.$refs.top.isStar = true;
            }
          });

        //专辑评论
        this.$http
          .get("/comment/", {
            params: {
              type: 2,
              tid: this.$route.query.id,
            },
          })
          .then((res) => {
            this.comment_list = res.data.data;
          });
      }
      //flag==2为歌单
      else if (flag == 2) {
        //歌单歌曲信息以及歌曲列表
        this.$http
          .get("/playlist", {
            headers: {
              Authorization:
                "Bearer " + JSON.parse(sessionStorage.getItem("token")),
            },
            params: {
              playlist_id: this.$route.query.id,
            },
          })
          .then((res) => {
            this.music_list = res.data.data.list;
            this.cover_img_path = res.data.data.cover;
            this.name = res.data.data.name;
            this.author = res.data.data.author;
            this.brief_info = res.data.data.description;
            this.issue_time = res.data.data.publish;
            this.like_data = res.data.data.fans;
            this.comment_data = res.data.data.comments;
            //处理页数问题
            let Cnt = res.data.data.list.length;
            this.songCnt = Cnt;
            this.pageCnt = Math.ceil(this.songCnt / 8);
            if (res.data.data.isStar == 1) {
              this.$refs.top.isStar = true;
            }
          });
        //歌单评论
        this.$http
          .get("/comment", {
            params: {
              type: 3,
              tid: this.$route.query.id,
            },
          })
          .then((res) => {
            this.comment_list = res.data.data;
          });
      }
    }
    //未登录时
    
    else {
      //flag==1为专辑
      if (flag == 1) {
        //专辑歌曲信息以及歌曲列表
        this.$http
          .get("/album", {
          
            params: {
              album_id: this.$route.query.id,
            },
          })
          .then((res) => {
            this.music_list = res.data.data.list;
            this.cover_img_path = res.data.data.cover;
            this.name = res.data.data.name;
            this.author = res.data.data.author;
            this.brief_info = res.data.data.description;
            this.issue_time = res.data.data.publish;
            this.like_data = res.data.data.fans;
            this.comment_data = res.data.data.comments;
            //处理页数问题
            let Cnt = res.data.data.list.length;
            this.songCnt = Cnt;
            this.pageCnt = Math.ceil(this.songCnt / 8);
            this.isStar = res.data.data.isStar;
            if (res.data.data.isStar == 1) {
              this.$refs.top.isStar = true;
            }
          });

        //专辑评论
        this.$http
          .get("/comment/", {
            params: {
              type: 2,
              tid: this.$route.query.id,
            },
          })
          .then((res) => {
            this.comment_list = res.data.data;
          });
      }
      //flag==2为歌单
      else if (flag == 2) {
        //歌单歌曲信息以及歌曲列表
        this.$http
          .get("/playlist", {
           
            params: {
              playlist_id: this.$route.query.id,
            },
          })
          .then((res) => {
            this.music_list = res.data.data.list;
            this.cover_img_path = res.data.data.cover;
            this.name = res.data.data.name;
            this.author = res.data.data.author;
            this.brief_info = res.data.data.description;
            this.issue_time = res.data.data.publish;
            this.like_data = res.data.data.fans;
            this.comment_data = res.data.data.comments;
            //处理页数问题
            let Cnt = res.data.data.list.length;
            this.songCnt = Cnt;
            this.pageCnt = Math.ceil(this.songCnt / 8);
            if (res.data.data.isStar == 1) {
              this.$refs.top.isStar = true;
            }
          });
        //歌单评论
        this.$http
          .get("/comment", {
            params: {
              type: 3,
              tid: this.$route.query.id,
            },
          })
          .then((res) => {
            this.comment_list = res.data.data;
          });
      }
    }
  },
};
</script>